
# coding: utf-8

# In[1]:

import numpy as np


# In[15]:

# 25 - Given a 1D array, negate all elements which are between 3 and 8, in place.
# (给定一个一维数组，将元素值在3至8之间的元素置为其原本的相反数)
arr1 = np.arange(11)
for i in arr1:
    if i > 3 and i <= 8:
        arr1[i] = (-1) * arr1[i]
print(arr1)
        


# In[18]:

#正确
arr1 = np.arange(11)
for i in arr1:
    if (i > 3) & (i <= 8):
        arr1[i] = (-1) * arr1[i]
print(arr1)


# In[19]:

#错误使用
arr1 = np.arange(11)
for i in arr1:
    if i > 3 & i <= 8:
        arr1[i] = (-1) * arr1[i]
print(arr1)


# In[20]:

#答案
Z = np.arange(11)
Z[(3 < Z) & (Z <= 8)] *= -1
print(Z)


# In[26]:

# 75 - How to swap two rows of an array? (如何交换一个数组的两行？)
arr2 = np.arange(25).reshape(5,5)
arr2


# In[29]:

arr23 = arr2[[1,0]]


# In[30]:

arr23


# In[31]:

a34 = arr2[[0,1]]


# In[32]:

a34


# In[33]:

arr2[[0,1]] = arr2[[1,0]]


# In[34]:

arr2


# In[ ]:



